/*
 *      Alumnos:
 * 
 *          - Trabes, Guillermo
 *          - Casanova, Matias
 * 
 *      Entrega final del trabajo practico de la materia Ingenieria de software
 *      2 de la Universidad Nacional de San Luis
 * 
 */
package concesionaria;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Concesionaria extends JFrame
        implements ActionListener {

    JDesktopPane desktop;

    public Concesionaria() {
        super("Concesionaria");

        //Make the big window be indented 50 pixels from each edge
        //of the screen.
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
                screenSize.width - inset * 2,
                screenSize.height - inset * 2);

        //Set up the GUI.
        desktop = new JDesktopPane(); //a specialized layered pane
        setContentPane(desktop);
        setJMenuBar(createMenuBar());

        //Make dragging a little faster but perhaps uglier.
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    }

    protected JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();

        //Set up the lone menu.
        JMenu clientes = new JMenu("Clientes");
        clientes.setMnemonic(KeyEvent.VK_C);
        menuBar.add(clientes);

        //Set up the first menu item.
        JMenuItem menuItem = new JMenuItem("Registrar Cliente");
        menuItem.setMnemonic(KeyEvent.VK_R);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_R, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("registrar_c");
        menuItem.addActionListener(this);
        clientes.add(menuItem);

        //Plan
        JMenu plan = new JMenu("Plan");
        plan.setMnemonic(KeyEvent.VK_P);
        menuBar.add(plan);



        menuItem = new JMenuItem("Inscribir Cliente a plan");
        menuItem.setMnemonic(KeyEvent.VK_I);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_I, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("insc_cli_pla");
        menuItem.addActionListener(this);
        plan.add(menuItem);


        JMenu autos = new JMenu("Autos");
        autos.setMnemonic(KeyEvent.VK_A);
        menuBar.add(autos);


        menuItem = new JMenuItem("Registrar entrega de Auto");
        menuItem.setMnemonic(KeyEvent.VK_X);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_X, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("entrega_de_auto");
        menuItem.addActionListener(this);
        autos.add(menuItem);


       

        menuItem = new JMenuItem("Listado Personas sin cancelar plan");
        menuItem.setMnemonic(KeyEvent.VK_L);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_L, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("listado_personas_sin_cancelar_plan");
        menuItem.addActionListener(this);
        plan.add(menuItem);
 
        
        
      
             
        menuItem = new JMenuItem("Listado Personas adquierieron auto por sorteo o licitacion");
        menuItem.setMnemonic(KeyEvent.VK_Z);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_Z, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("listado_personas_adquirieron_auto_sorteo_o_licitacion");
        menuItem.addActionListener(this);
        
        clientes.add(menuItem);
        
        
        
        menuItem = new JMenuItem("Estadisticas de autos mas vendidos por año");
        menuItem.setMnemonic(KeyEvent.VK_D);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_D, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("EAMVPA");
        menuItem.addActionListener(this);
       
        autos.add(menuItem);

        //Acerca del software
        JMenu acerca = new JMenu("Acerca");
        acerca.setMnemonic(KeyEvent.VK_C);
        menuBar.add(acerca);

        //Salir
        menuItem = new JMenuItem("Salir");
        menuItem.setMnemonic(KeyEvent.VK_S);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S, ActionEvent.ALT_MASK));
        menuItem.setActionCommand("quit");
        menuItem.addActionListener(this);
        acerca.add(menuItem);

        return menuBar;
    }

    //React to menu selections.
    public void actionPerformed(ActionEvent e) {
        if ("registrar_c".equals(e.getActionCommand())) { //new
            RegistrarC();
        }
        if ("insc_cli_pla".equals(e.getActionCommand())) { //new
            inscCliPlan();
        }
        if ("entrega_de_auto".equals(e.getActionCommand())) {
            entregaDeAuto();
        }
        if("listado_personas_sin_cancelar_plan".equals(e.getActionCommand())){
            listadoPersonasSinCancelarPlan();
        }
        
        if("listado_personas_adquirieron_auto_sorteo_o_licitacion".equals(e.getActionCommand())){
            LPAASOL();
        }
        
         if("EAMVPA".equals(e.getActionCommand())){
            AutosMasVend();
        }
        
        
        
        if ("quit".equals(e.getActionCommand())) {
            quit();
        }
    }

    //LLamo a registrar Cliente:
    protected void RegistrarC() {
        VentanaRegCliente frame = new VentanaRegCliente();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }
    //Llamo a inscribir cliente a plan

    protected void inscCliPlan() {
        VentanaInscClientePlan frame = new VentanaInscClientePlan();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    protected void entregaDeAuto() {
        VentanaEntregaDeAuto frame = new VentanaEntregaDeAuto();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    protected void listadoPersonasSinCancelarPlan() {
        VentanaPersonasSinCancelarPlan frame = new VentanaPersonasSinCancelarPlan();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
          
         
    }
    
    protected void LPAASOL() {
      VentanaSorteoLicitacion frame = new VentanaSorteoLicitacion();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }
    
    
    protected void AutosMasVend() {
       VentanaAutosMasVendidos frame = new VentanaAutosMasVendidos();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        } 
    }
    
    //Salir De la aplicacion
    protected void quit() {
        System.exit(0);
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        Concesionaria frame = new Concesionaria();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Display the window.
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                DBCon.Inicializar();
                createAndShowGUI();
            }
        });
    }
}
